<?php
/**
 * Created by PhpStorm.
 * User: tangyunfei
 * Date: 2018/11/15
 * Time: 15:12
 */
class VipAction extends  Action{
    private $uinfo = 0;
    private $uid;
    private $company_id;
    function __construct(){

        parent::__construct();
        $this->uinfo = checkUserCookie();
        $id = empty($_GET['id'])?Exit():$_GET['id'];
        $company =M('Company')->where("id=".$id)->find();
        $this->uid = $company['uid'];
        $this->company_id = $company['id'];
        $this->assign("company",$company);
        $this->assign("url","http://www.yeczx.com");

    }

    function index(){

        $temp = M('Zhaopin')->where("uid=".$this->uid)->limit(13)->select();
        foreach ($temp as $v){
            $v['cate'] =M('Category')->where("id=".$v['cid'])->getField("path");
            $v['city'] = M('City')->where("id=".$v['cityid'])->getField("pinyin");
            $info[]=$v;
        }
        $this->assign("info",$info);

        $this->news =M('CompanyNews')->where("status=1 and uid=".$this->uid)->limit(8)->select();

        $temp1=M('Zhaopin')->where("status=1")->limit(15)->select();
        foreach ($temp1 as $v){
            $v['cate'] =M('Category')->where("id=".$v['cid'])->getField("path");
            $v['city'] = M('City')->where("id=".$v['cityid'])->getField("pinyin");
            $products[]=$v;
        }
        $this->assign("products",$products);

        import('ORG.Util.Page');// 导入分页类
        $count      = M('CompanyFeedback')->where("company_id=".$this->company_id)->count();// 查询满足要求的总记录数
        $Page       = new Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数
        $show       = $Page->show();// 分页显示输出

        $feedback =M('CompanyFeedback')->where("company_id=".$this->company_id)->limit($Page->firstRow.','.$Page->listRows)->order("id DESC")->select();
        $this->assign('feedback',$feedback);// 赋值数据集
        $this->assign('page',$show);


        $this->display();
    }

    /**
     * 产品系想你
     * Enter description here ...
     */
    function product(){

        $id = empty($_GET['id'])?Exit():$_GET['id'];

        import('ORG.Util.Page');// 导入分页类
        $count      = M('Zhaopin')->where('uid='.$this->uid)->count();// 查询满足要求的总记录数
        $Page       = new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
        $show       = $Page->show();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $temp = M('Zhaopin')->where('uid='.$this->uid)->order('createtime DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
        foreach ($temp as $v){
            $v['cate'] =M('Category')->where("id=".$v['cid'])->getField("path");
            $v['city'] = M('City')->where("id=".$v['cityid'])->getField("pinyin");
            $list[]=$v;
        }
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出
        $this->display(); // 输出模板




    }

    /**
     * 荣誉
     * Enter description here ...
     */
    function honour(){
        $id = empty($_GET['id'])?Exit():$_GET['id'];
        $info = M('Company')->where("id=".$id)->find();

        import('ORG.Util.Page');// 导入分页类
        $count      = M('company_rongyu')->where("company_id=".$this->company_id)->count();// 查询满足要求的总记录数
        $Page       = new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
        $show       = $Page->show();// 分页显示输出

        $list =M('company_rongyu')->where("company_id=".$this->company_id)->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign("info",$info);
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);
        $this->display();

    }


    /**
     * 动态
     * Enter description here ...
     */
    function trends(){

        $id = empty($_GET['id'])?Exit():$_GET['id'];
        //$info = M('Company')->where("id=".$id)->find();

        import('ORG.Util.Page');// 导入分页类
        $count      = M('company_news')->where("company_id=".$this->company_id)->count();// 查询满足要求的总记录数
        $Page       = new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
        $show       = $Page->show();// 分页显示输出

        $list =M('company_news')->where("company_id=".$this->company_id)->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign("info",$info);
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);
        $this->display();


    }


    /*
     * 公司新闻详情
     */
    function viewnews(){
        $this->info = M('company_news')->where("status=1 and id=".$_GET['vid'])->find();

        $this->display();
    }

    /*
     * 荣誉详情
     */
    function viewrongyu(){
        $this->info = M('company_rongyu')->where("status=1 and id=".$_GET['vid'])->find();

        $this->display();
    }


    /*
     * 联系我们
     * Enter description here ...
     */
    function contact(){

        $id = empty($_GET['id'])?Exit():$_GET['id'];
        $info = M('Company')->where("id=".$id)->find();


        $this->assign("info",$info);
        $this->display();

    }


    /***
     * 在线留言
     */
    function feedback(){
        $id = empty($_GET['id'])?Exit():$_GET['id'];
        if(isset($_POST['submit'])){
            $data['company_id'] = $id;
            $data['lxren']=$_POST['lxren'];
            $data['lxtel']=$_POST['lxtel'];
            $data['lxqq']=$_POST['lxqq'];
            $data['neirong']=$_POST['neirong'];
            $data['createtime']=mktime();
            if(M('company_feedback')->add($data)){
                header("Location:".'product.html');
                exit();
            }
        }else{
            $info = M('Company')->where("id=".$id)->find();
            $this->assign("info",$info);
            $this->display();
        }
    }
}